<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>悬停染色</title>
    <style type="text/css">
        div {
            border: black 1px solid;
            position: relative;
        }

        #d1 {
            width: 250px;
            height: 250px;
            left: 25px;
            top: 25px;
        }

        #d2 {
            width: 200px;
            height: 200px;
            left: 25px;
            top: 25px;
        }

        #d3 {
            width: 150px;
            height: 150px;
            left: 25px;
            top: 25px;
        }

        #d4 {
            width: 100px;
            height: 100px;
            left: 25px;
            top: 25px;
        }

        #d5 {
            width: 50px;
            height: 50px;
            left: 25px;
            top: 25px;
        }
    </style>

</head>
<body>
<div id="d1">
    <div id="d2">
        <div id="d3">
            <div id="d4">
                <div id="d5"></div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    let divs = document.querySelectorAll("div");
    for (let i = 0; i < divs.length; i++) {
        divs[i].onmouseover = function () {
            //window.event.target.setAttribute("style", "background-color:gray;");
            this.setAttribute("style", "background-color:gray;");
        }
        divs[i].onmouseout = function () {
            window.event.target.setAttribute("style", "background-color:white;")
        }
    }
</script>
</body>
</html>